<template>
	<view>
		<view class="swiper" style="background-color: #fff;padding: 20rpx;">
			<u-swiper :list="swiperList" @click="to" height="300"></u-swiper>
		</view>
		<u-gap height="20" bg-color="#f7f7f7"></u-gap>
		<view class="news" style="margin-top: 20rpx;">
			<u-sticky offset-top="0">
				<u-tabs :list="tabList" :is-scroll="true" :current="tabCurrent" @change="tabChange"></u-tabs>
			</u-sticky>
			<view class="news-list" style="background-color: #fff;padding: 20rpx;">
				<view class="news-item" v-for="item in newsList" style="display: flex;flex-direction: row;
				justify-content: space-between;padding: 20rpx 0;border-top: 2rpx solid #e4e7ed;">
					<view class="left" style="width: 450rpx;">
						<view class="top" style="height: 168rpx;">
							<text style="font-size: 32rpx;font-weight: bold;line-height: 1.5;
							display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;
							overflow: hidden;">{{item.title}}</text>
							<rich-text style="display: -webkit-box;-webkit-box-orient: vertical;-webkit-line-clamp: 2;
							overflow: hidden;line-height: 1.5;font-size: 26rpx;" :nodes="item.content"></rich-text>
						</view>
						<view class="bottom" style="display: flex;flex-direction: row;font-size: 22rpx;color: #666;">
							<text>{{item.readNum}} 阅读</text>
							<text style="margin-left: 20rpx;">{{item.publishDate}}</text>
						</view>
					</view>
					<view class="right center">
						<navigator :url="`/pages/news-detail/news-detail?id=${item.id}`">
							<image :src="$baseUrl + item.cover" mode="" style="width: 250rpx;height: 200rpx;"></image>
						</navigator>
					</view>
				</view>
				<u-divider>没有更多了</u-divider>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [],
				tabList: [],
				tabCurrent: 0,
				newsList: []
			};
		},
		onLoad() {
			this.getSwiper()
			this.getTab()
		},
		methods: {
			getSwiper(){
				this.$request({
					url: '/prod-api/api/rotation/list',
					data:{
						type: '2'
					}
				}).then(res => {
					console.log(res)
					this.swiperList = res.rows.map(item => ({image: this.$baseUrl + item.advImg, id: item.targetId}))
				})
			},
			tabChange(index){
				this.tabCurrent = index
				this.getNews()
			},
			getTab(){
				this.$request({
					url: '/prod-api/press/category/list'
				}).then(res => {
					console.log(res)
					this.tabList = res.data.map(item => ({name: item.name, id: item.id}))
					this.getNews()
				})
			},
			getNews(){
				this.$request({
					url: '/prod-api/press/press/list',
					data: {
						type: this.tabList[this.tabCurrent].id
					}
				}).then(res => {
					console.log(res)
					this.newsList = res.rows.sort((a,b) => {
						return new Date(b.publishDate).getTime() - new Date(a.publishDate).getTime()
					})
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
